package 剑指offer_leetcode;

/**
 * JZ18删除链表的节点
 */

public class 剑指Offer18_删除链表的节点 {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode res = new ListNode(0);
        res.next = head;
        ListNode cur = head;
        ListNode pre =res;
        while(cur!=null){
            if(cur.val==val)
                pre.next = cur.next;
            pre = cur;
            cur = cur.next;
        }
        return res.next;
    }
}
